package com.test;

import java.util.Scanner;

/**
 *@Author: Solitude
 *@Data: 2024/5/7 01:04
 *@Description:
 */
public class Reverse {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        int k = scanner.nextInt();
        System.out.println(getResult(s, k));
    }

    public static String getResult(String s, int k) {
        String result = "";
        int count = 0;
        for (int i = 0; i < s.length() / k; i++) {
            if (i % 2 != 0) {
                result = s.substring(k * i, k * (i + 1)) + "111";
            } else {
                result = result + new StringBuffer(s.substring(k * i, k * (i + 1))).reverse();
            }
            count++;
        }
        result = result + s.substring(k * count, s.length());
        return result;
    }
}
